package com.hm.common.autoconfigure;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @author shishun.wang
 * @version 1.0
 * @date 2019/5/3 11:04
 * @describe
 */
@Configuration
@EnableSwagger2
@Profile({ "dev", "test" })
public class SwaggerConfig {

    @Autowired
    private CommonProperties commonProperties;

    @Bean
    public Docket productApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.basePackage(commonProperties.getSwagger().getBasePackage()))
                .paths(PathSelectors.any())
                .build()
                .apiInfo(metaData());
    }
    private ApiInfo metaData() {
        return new ApiInfoBuilder()
                .title(commonProperties.getSwagger().getTitle())
                .description(commonProperties.getSwagger().getDescription())
                .version(commonProperties.getSwagger().getVersion())
                .license(commonProperties.getSwagger().getLicense())
                .licenseUrl(commonProperties.getSwagger().getLicenseUrl())
                .build();
    }
}
